// pages/ptgoods/ptgoods.js

const util = require('../../utils/util.js');
const api = require('../../config/api.js');
const user = require('../../utils/user.js');
const WxParse = require('../../wxParse/wxParse.js');

const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    d: '',
    h: '',
    m: '',
    s: '',
    end:'',
    id:'',
    imgUrls: [
     
    ],
    detailss: [
    ],
    pt:[],
    goods: {
      time: '12天:12时:12分:12秒',
      oldprice: 23,
      newprice: 12,
      vipprice: 10,
      reduce: 9,
      pepole: 2,
      hassail: 4,
      success: 8,
      name: '月季'
    }
  },
  gopt(e){
    console.log(e)
    wx.navigateTo({
      url: '../ptshop/ptshop?id=' + this.data.goods.id + "&userid=" + e.currentTarget.dataset.id,
    })
  },
  getzhinan() {
    let that = this
    util.request(api.QueryListGuide, {
    }, {
        'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
        'X-Qxmall-Token': wx.getStorageSync('token')
      }).then(function (res) {
        console.log(res.data)
        if (res.code == 200) {
          that.setData({
            detailss: res.data.listGuide
          })
        }
      })
  },

  queryUserComm() {
    let that = this
    util.request(api.QueryGroupIdInfo+"?id="+that.data.id, {
    }, 'get', {
      }).then(function (res) {
        console.log(res)
        // var end = res.data.groupInfo.endTime
        // var timer = setInterval(function () {
        //   console.log(end)
        //   var time3 = util.daojishi2('2018-2-14,23:10:59')
        //   console.log(time3)
        // }, 1000);
        var times = setInterval(function () {
          var start = new Date();  //开始时间
          var end = new Date(res.data.groupInfo.endTime);//结束时间，可以设置时间
          //parseInt()取整
          var result = parseInt((end.getTime() - start.getTime()) / 1000);//计算出豪秒
          var d = parseInt(result / (24 * 60 * 60));//用总共的秒数除以1天的秒数
          var h = parseInt(result / (60 * 60) % 24);//精确小时，用去余
          var m = parseInt(result / 60 % 60);//剩余分钟就是用1小时等于60分钟进行趣余
          var s = parseInt(result % 60);
          //当倒计时结束时，改变内容
          that.setData({
            d: d,
            h: h,
            m: m,
            s: s
          })
        }, 1000)
        console.log(res.data.groupInfo.neceInfo.imgRoll)
        let ceshi = res.data.groupInfo.neceInfo.content
        WxParse.wxParse('article', 'html', ceshi, that, 5); 
       that.setData({
         end: res.data.groupInfo.endTime,
         goods: res.data.groupInfo,
       })
        var words = res.data.groupInfo.neceInfo.imgRoll;     //字符串中间已特殊符号隔开
        var words1 = words.split("]");
        var words2 = words1[0].split("[");   //转成数组类似php的explode函数
        // console.log(words2)
        let imgurl = that.data.imgUrls
        words2[1] = words2[1].replace(/\"/g, "");
        var bb = words2[1].split(",");
        console.log(bb)
        imgurl.push(bb)
        that.setData({
          imgUrls: bb
        })
      });
  },

addpt(e){
  console.log(e)
  wx.navigateTo({
    url: '../Order/Order?id=' + this.data.goods.id + '&state=' + e.currentTarget.dataset.id
  })
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    this.setData({
      id: options.id
    })
    
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.queryUserComm()
    this.getzhinan()
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})